#!/bin/sh -e
# Copyright (c) 2016 The crouton Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
if [ "${TARGETNOINSTALL:-c}" = 'c' ] &&
        [ "$DISTRO" = 'debian' -o "$DISTRO" = 'kali' ]; then
    error 99 "touch target is not supported on Debian."
fi
REQUIRES='x11'
DESCRIPTION='Touchscreen and limited generic gesture support.'
. "${TARGETSDIR:="$PWD"}/common"

### Append to prepare.sh:
if release -lt raring; then
    # As of 2013-01-30, pre-Raring touchegg is useless. Download it manually.
    install_mirror_package 'touchegg' 'pool/universe/t/touchegg'
else
    install --minimal touchegg
fi

# The global config file.
cat > /etc/touchegg.conf <<EOF
<touchégg>
	<settings>
		<property name="composed_gestures_time">0</property>
	</settings>
	<application name="All">
		<gesture type="DRAG" fingers="1" direction="ALL">
			<action type="SCROLL">SPEED=5:INVERTED=true</action>
		</gesture>
		<gesture type="PINCH" fingers="5" direction="OUT">
			<action type="SHOW_DESKTOP"></action>
		</gesture>
		<gesture type="DRAG" fingers="5" direction="UP">
			<action type="SHOW_DESKTOP"></action>
		</gesture>
		<gesture type="PINCH" fingers="4" direction="IN">
			<action type="MINIMIZE_WINDOW"></action>
		</gesture>
		<gesture type="PINCH" fingers="4" direction="OUT">
			<action type="MAXIMIZE_RESTORE_WINDOW"></action>
		</gesture>
		<gesture type="DRAG" fingers="4" direction="LEFT">
			<action type="MOVE_WINDOW"></action>
		</gesture>
		<gesture type="PINCH" fingers="5" direction="IN">
			<action type="CLOSE_WINDOW"></action>
		</gesture>
		<gesture type="DRAG" fingers="5" direction="DOWN">
			<action type="CLOSE_WINDOW"></action>
		</gesture>
		<gesture type="DRAG" fingers="4" direction="DOWN">
			<action type="MINIMIZE_WINDOW"></action>
		</gesture>
		<gesture type="DRAG" fingers="4" direction="UP">
			<action type="MAXIMIZE_RESTORE_WINDOW"></action>
		</gesture>
		<gesture type="TAP" fingers="3" direction="">
			<action type="MOUSE_CLICK">BUTTON=2</action>
		</gesture>
		<gesture type="TAP" fingers="2" direction="">
			<action type="MOUSE_CLICK">BUTTON=3</action>
		</gesture>
		<gesture type="DRAG" fingers="3" direction="ALL">
			<action type="CHANGE_DESKTOP"></action>
		</gesture>
		<gesture type="TAP" fingers="1" direction="">
			<action type="MOUSE_CLICK">BUTTON=1</action>
		</gesture>
		<gesture type="DRAG" fingers="4" direction="RIGHT">
			<action type="MOVE_WINDOW"></action>
		</gesture>
	</application>
	<application name="Okular, Gwenview">
		<gesture type="ROTATE" fingers="2" direction="LEFT">
			<action type="SEND_KEYS">Control+L</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="IN">
			<action type="SEND_KEYS">Control+KP_Add</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="OUT">
			<action type="SEND_KEYS">Control+KP_Subtract</action>
		</gesture>
		<gesture type="ROTATE" fingers="2" direction="RIGHT">
			<action type="SEND_KEYS">Control+R</action>
		</gesture>
	</application>
	<application name="Google-chrome, Firefox, Dolphin, Chromium-browser">
		<gesture type="DRAG" fingers="2" direction="DOWN">
			<action type="SEND_KEYS">Control+minus</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="IN">
			<action type="SEND_KEYS">Control+minus</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="OUT">
			<action type="SEND_KEYS">Control+equal</action>
		</gesture>
		<gesture type="DRAG" fingers="2" direction="RIGHT">
			<action type="SEND_KEYS">Alt+Left</action>
		</gesture>
		<gesture type="DRAG" fingers="2" direction="UP">
			<action type="SEND_KEYS">Control+equal</action>
		</gesture>
		<gesture type="DRAG" fingers="2" direction="LEFT">
			<action type="SEND_KEYS">Alt+Right</action>
		</gesture>
	</application>
	<application name="Evince">
		<gesture type="ROTATE" fingers="2" direction="LEFT">
			<action type="SEND_KEYS">Control+Right</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="IN">
			<action type="SEND_KEYS">Control+KP_Add</action>
		</gesture>
		<gesture type="PINCH" fingers="2" direction="OUT">
			<action type="SEND_KEYS">Control+KP_Subtract</action>
		</gesture>
		<gesture type="ROTATE" fingers="2" direction="RIGHT">
			<action type="SEND_KEYS">Control+Left</action>
		</gesture>
	</application>
</touchégg>
EOF
